// Copyright 2022 jeff.li. and/or its affiliates.


#include <tbir/runtime/container.h>
#include <tbir/runtime/container_private.h>
#include <tbir/runtime/future_wrap.h>
#include <tbir/runtime/registry.h>

namespace tbir::runtime {

    TBIR_REGISTER_GLOBAL("runtime.Future").set_body([](PyArgs args) -> RTValue {
        MXCHECK_EQ(args.size(), 1) << "[Future][func: Future] Expect 1 arguments but get " << args.size();
        UserDataRef op = args[0].AsObjectRef<UserDataRef>();
        return Future::make_future_udref([op]() -> RTValue { return op.call(); });
    });

    TBIR_REGISTER_GLOBAL("runtime.Future_Get").set_body([](PyArgs args) -> RTValue {
        MXCHECK_EQ(args.size(), 1) << "[Future][func: get] Expect 1 arguments but get " << args.size();
        UserDataRef udref = args[0].AsObjectRef<UserDataRef>();
        Future *future =
                static_cast<Future *>((static_cast<NativeObject *>(udref.ud_ptr())->opaque_ptr_).get());
        return future->get();
    });

}  // namespace tbir::runtime
